PROCEDURE LongRealToString (x: LONGREAL; VAR s: ARRAY OF CHAR);
PROCEDURE StringToInt (s: ARRAY OF CHAR; VAR x, res: LONGINT);
PROCEDURE StringToReal (s: ARRAY OF CHAR; VAR x: LONGREAL; VAR res: LONGINT);
END Strings.
CONST charCode
Possible value for parameter form of IntToStringForm, asking for formatting integers following the syntax of Oberon numerical character literals, e.g. 0DX or 37X.
CONST decimal
Possible value for parameter form of IntToStringForm, asking for formatting integers as decimal literals.
CONST hexadecimal
Possible value for parameter form of IntToStringForm, asking for formatting integers as hexadecimal literals.
CONST digitspace
A digit space has the width of digit zero (0) which is equivalent to the width of all digits in most fonts, thus can be used for number formatting.
PROCEDURE Valid (VAR s: ARRAY OF CHAR): BOOLEAN;
Returns TRUE if and only if the array s contains at least one string terminator 0X.
s = s'
s contains a valid string value =>
EXIST i, 0 <= i < LEN(s): s[i] = 0X
s does not contain a valid string value =>
ALL i IN RANGE 0 .. LEN(s)-1: s[i] # 0X
PROCEDURE Len (VAR s: ARRAY OF CHAR): LONGINT;
Returns the position of the first occurrence of the string terminator 0X in s.
Valid(s) (not checked)
s = s'
0 <= Len(s) < LEN(s)
FORALL i IN RANGE [0 .. Len(s)): s[i] # 0X
PROCEDURE Upper (ch: CHAR): CHAR;
PROCEDURE Lower (ch: CHAR): CHAR;
Conversion to uppercase and lowercase characters. Handles the entire ISO Latin-1 character set. Character values that have no uppercase or lowercase aequivalent are returned unchanged.
PROCEDURE ToLower (VAR in: ARRAY OF CHAR; VAR out: ARRAY OF CHAR);
Converts string in to lowercase characters and returns the result in out. Handles the entire ISO Latin-1 character set. Character values that have no lowercase equivalent are unchanged. The same actual parameter may be passed for in and out.
Valid(in) index trap
Valid(out)
FORALL i IN RANGE [0 .. MIN(Len(in), LEN(out)-1): out[i] = Lower(in[i])
PROCEDURE ToUpper (VAR in: ARRAY OF CHAR; VAR out: ARRAY OF CHAR);
Converts string in to uppercase characters and returns the result in out. Handles the entire ISO Latin-1 character set. Character values that have no uppercase equivalent are unchanged. The same actual parameter may be passed for in and out.
Valid(in) index trap
Valid(out)
FORALL i IN RANGE [0 .. MIN(Len(in), LEN(out)-1): out[i] = Upper(in[i])
PROCEDURE Concat (s1, s2: ARRAY OF CHAR; VAR res: ARRAY OF CHAR);
Appends string s2 to s1 and returns the result in res. If res is not large enough to hold the result, the result is truncated.
Valid(s1) & Valid(s2) (not checked)
Len(res) = MIN(Len(s1)+Len(s2), LEN(res)-1)
FORALL i IN RANGE [0 .. MIN(Len(s1), LEN(res)-1): res[i] = s1[i]
FORALL i IN RANGE [Len(s1) .. MIN(Len(s1) + Len(s2), LEN(res)-1): res[i] = s2[i-Len(s1)]
PROCEDURE Append (VAR s: ARRAY OF CHAR; suffix: ARRAY OF CHAR);
Appends the string suffix to s. Except for performance, Append(s, suffix) is equivalent to Concat(s, suffix, s)
PROCEDURE Extract (VAR s: ARRAY OF CHAR; pos, len: LONGINT; VAR res: ARRAY OF CHAR);
Extracts the stretch [pos, MIN(pos+len, Len(s))) from s and returns it in res. The result is truncated if res is not large enough. The same actual parameter may be passed for s and res.
FORALL i IN RANGE [0 .. Len(res)): res[i] := s'[pos+i]
PROCEDURE Replace (VAR s: ARRAY OF CHAR; pos, len: LONGINT; rep: ARRAY OF CHAR);
Replaces the stretch [pos, MIN(pos+len, Len(s))) in s with the string in rep. The characters after the replaced stretch are moved if necessary. The result is truncated if s is not large enough.
len >= 0 20
pos >= 0 21
Valid(s) & Valid(rep) (not checked)
Valid(res)
FORALL i IN RANGE [0 .. MIN(pos, Len(s')): s[i] := s'[i]
FORALL i IN RANGE [pos .. MIN(pos+Len(rep), LEN(s)-1): s[i] = rep[i-pos]
FORALL i IN RANGE [pos+Len(rep) .. MIN(Len(s')-len+Len(rep), LEN(s) -1): s[i] := s'[i+len-Len(rep)]
Hint: if len = 0 then rep is inserted in s at position pos. If Len(rep) = 0 then the stretch [pos, MIN(pos+len, Len(s))) is deleted from s.
PROCEDURE Find (VAR s: ARRAY OF CHAR; pat: ARRAY OF CHAR; start: LONGINT;
VAR pos: LONGINT);
Searches the first occurrence of the pattern pat in string s after position start. If the pattern is found, the position of the first character of the pattern in s is returned in pos. If the pattern is not found, pos is -1.
start >= 0 20
Valid(s) & Valid(pat) (not checked)
s = s'
(* Match(pos) == FORALL i IN RANGE [0 .. Len(pat)): s[i+pos] = pat[i] *)
pos = -1 =>
FORALL i IN RANGE [start, Len(s)-Len(pat)]: ~Match(i)
Convert integer x into string s. If form is charCode or hexadecimal, x is converted to a base 16 representation. The total representation will at least have a width of minWidth characters, where padding (if required) takes place to the left using characters as specified by fillCh.
If suffix is TRUE, a suffix character is appended to the number representation according to the number form. The value form = charCode renders the suffix "X", while form = hexadecimal renders the suffix "H".
decimal representations of negative integers are formed using a base
complement form of width minWidth. E.g., x = -3 renders for base = 16 and minWidth = 4 as "FFFD".
(form = charCode) OR (form = decimal) OR (form = hexadecimal) 20
minWidth >= 0 22
PROCEDURE IntToString (x: LONGINT; VAR s: ARRAY OF CHAR)
Write integer in default format. Except for performance, equivalent to:
Convert real x into string s. The string created to represent the number is either in fixed point or in scientific format, according to expW. precision denotes the number of valid decimal places (usually 7 for reals and 16 for long reals). minW denotes the minimal length in characters. If necessary, preceding fillCh will be inserted. Numbers are always rounded to the last valid and visible digit.
expW > 0: exponential format (scientific) with at least expW digits in the exponent.
expW = 0: fixpoint or floatingpoint format, depending on x.
expW < 0: fixpoint format with -expW digits after the decimal point.
0 < precision <= 16 20
0 <= minW < LEN(s) 21
-LEN(s) < expW <= 3 22
PROCEDURE RealToString (x: REAL; VAR s: ARRAY OF CHAR)
Write real in default format. Except for performance, equivalent to:
RealToStringForm(x, 7, 0, 0, digitspace, s)
PROCEDURE LongRealToString (x: LONGREAL; VAR s: ARRAY OF CHAR)
Write long real in default format. Except for performance, equivalent to:
RealToStringForm(x, 16, 0, 0, digitspace)
PROCEDURE StringToInt (s: ARRAY OF CHAR; VAR x: LONGINT; VAR res: LONGINT)
Converts the number contained in string s into value x. Legal integer number representations follow the syntax given below. Possible result codes are res = 1 for overflow, res = 2 for syntax error.